package com.wc.算法提高课.F第六章_基础算法.排序.动态中位数;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/2 11:44
 * @description https://www.acwing.com/problem/content/description/108/
 */
public class Main {
    /**
     * 思路：
     * 中位数, 前面一半有序, 后面一半有序
     * 那么可以使用堆排序来处理
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;

    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        for (int t = 1; t <= T; t++) {
            PriorityQueue<Integer> last = new PriorityQueue<>();
            PriorityQueue<Integer> pre = new PriorityQueue<>(Comparator.reverseOrder());
            int code = sc.nextInt();
            n = sc.nextInt();
            out.printf("%d %d\n", code, (n + 1) / 2);
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt();
                if (pre.isEmpty() || x <= pre.peek()) pre.add(x);
                else last.add(x);
                if (pre.size() > last.size() + 1) last.add(pre.poll());
                if (last.size() > pre.size()) pre.add(last.poll());
                if ((i & 1) == 0) {
                    out.print(pre.peek() + " ");
                    if (++cnt % 10 == 0) out.println();
                }
            }
            if (cnt % 10 > 0) out.println();
        }
        out.flush();
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
